process.mixin(GLOBAL, require('sys'));

/**
 *
 */
exports.isNumber = function(object) {
  return Object.prototype.toString.call(object) === '[object Number]';
};

/**
 * @param scope string The scope to bind the function to permanently
 */
Function.prototype.bind = function(scope) {
  var method = this;
  return function() {
    return method.apply(scope, arguments); 
  };
};

/**
 * Create a property on the supplied object that is wrapped with getters/setters
 * Also, if the obj is an EventEmitter, it will emit an event when the property has changed
 *
 * @param obj Object The object to add the property too
 * @param name String The name of the proeprty
 * @param initial Object The initial value of the property
 * @param readonly Boolean Flag to add a setter or not
 */
exports.property = function(obj, name, initial, readonly) {
  var val = initial || null;
  var oldval = null;

  obj.__defineGetter__(name, function() {
    return val; 
  });

  if(!readonly) {
    obj.__defineSetter__(name, function(newval) { 
      if(newval !== val) {
        val = newval; 

        //Emit an event
        obj.emit(name, {
          name: name,
          createtime: new Date().getTime(),
          elapsed: 0,
          data: newval
        });
      }
    });
  }
};

/**
exports.merge = function(obj, newobj) {
  if(!newobj){
     return;
  }
  for(var i in newobj) {
    obj[i]  = newobj[i];
  }

  return obj;
};
*/
